<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="js/vue-2.5.7.js"></script>
</head>
<body>

<div id="app">
   <span>{{selected}}</span>
    <button @click="handleBtn"></button>
</div>
<script>
    const app = new Vue({
        el: '#app',
        data: {
            selected:'初始值'
        },
        methods: {
            handleBtn(){
                let tmp=Math.random();
                this.selected=tmp;
                console.log("赋值的是:"+tmp);
            }
        },
        watch:{
            //当selected值发生变化时，会调用这个函数
            selected(newValue,oldValue){
                console.log("new:"+newValue);
                console.log("old:"+oldValue);
            }
        }
    });
</script>
</body>
</html>